/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Adam
 */
@Entity
@Table(name = "users")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
    @NamedQuery(name = "Users.findByUserId", query = "SELECT u FROM Users u WHERE u.userId = :userId"),
    @NamedQuery(name = "Users.findByLogin", query = "SELECT u FROM Users u WHERE u.login = :login"),
    @NamedQuery(name = "Users.findByPassword", query = "SELECT u FROM Users u WHERE u.password = :password"),
    @NamedQuery(name = "Users.findByEmail", query = "SELECT u FROM Users u WHERE u.email = :email"),
    @NamedQuery(name = "Users.findByNPolice", query = "SELECT u FROM Users u WHERE u.nPolice = :nPolice"),
    @NamedQuery(name = "Users.findByNPatrol", query = "SELECT u FROM Users u WHERE u.nPatrol = :nPatrol"),
    @NamedQuery(name = "Users.findByNAccident", query = "SELECT u FROM Users u WHERE u.nAccident = :nAccident"),
    @NamedQuery(name = "Users.findByNMobileradar", query = "SELECT u FROM Users u WHERE u.nMobileradar = :nMobileradar"),
    @NamedQuery(name = "Users.findByForgottenPwHash", query = "SELECT u FROM Users u WHERE u.forgottenPwHash = :forgottenPwHash"),
    @NamedQuery(name = "Users.findByAreas", query = "SELECT u FROM Users u WHERE u.areas = :areas")})
public class Users implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
    private Collection<Routes> routesCollection;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "user_id")
    private Integer userId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 15)
    @Column(name = "login")
    private String login;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "password")
    private String password;
    // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 50)
    @Column(name = "email")
    private String email;
    @Basic(optional = false)
    @NotNull
    @Column(name = "n_police")
    private int nPolice;
    @Basic(optional = false)
    @NotNull
    @Column(name = "n_patrol")
    private int nPatrol;
    @Basic(optional = false)
    @NotNull
    @Column(name = "n_accident")
    private int nAccident;
    @Basic(optional = false)
    @NotNull
    @Column(name = "n_mobileradar")
    private int nMobileradar;
    @Size(max = 200)
    @Column(name = "forgotten_pw_hash")
    private String forgottenPwHash;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 200)
    @Column(name = "areas")
    private String areas;
    @Lob
    @Size(max = 65535)
    @Column(name = "keywords")
    private String keywords;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "userId")
    private Collection<Reports> reportsCollection;
    @JoinColumn(name = "user_role_id", referencedColumnName = "user_role_id")
    @ManyToOne(optional = false)
    private UserRole userRoleId;

    public Users() {
    }

    public Users(Integer userId) {
        this.userId = userId;
    }

    public Users(Integer userId, String login, String password, String email, int nPolice, int nPatrol, int nAccident, int nMobileradar, String areas) {
        this.userId = userId;
        this.login = login;
        this.password = password;
        this.email = email;
        this.nPolice = nPolice;
        this.nPatrol = nPatrol;
        this.nAccident = nAccident;
        this.nMobileradar = nMobileradar;
        this.areas = areas;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getNPolice() {
        return nPolice;
    }

    public void setNPolice(int nPolice) {
        this.nPolice = nPolice;
    }

    public int getNPatrol() {
        return nPatrol;
    }

    public void setNPatrol(int nPatrol) {
        this.nPatrol = nPatrol;
    }

    public int getNAccident() {
        return nAccident;
    }

    public void setNAccident(int nAccident) {
        this.nAccident = nAccident;
    }

    public int getNMobileradar() {
        return nMobileradar;
    }

    public void setNMobileradar(int nMobileradar) {
        this.nMobileradar = nMobileradar;
    }

    public String getForgottenPwHash() {
        return forgottenPwHash;
    }

    public void setForgottenPwHash(String forgottenPwHash) {
        this.forgottenPwHash = forgottenPwHash;
    }

    public String getAreas() {
        return areas;
    }

    public void setAreas(String areas) {
        this.areas = areas;
    }

    public String getKeywords() {
        return keywords;
    }

    public void setKeywords(String keywords) {
        this.keywords = keywords;
    }

    @XmlTransient
    public Collection<Reports> getReportsCollection() {
        return reportsCollection;
    }

    public void setReportsCollection(Collection<Reports> reportsCollection) {
        this.reportsCollection = reportsCollection;
    }

    public UserRole getUserRoleId() {
        return userRoleId;
    }

    public void setUserRoleId(UserRole userRoleId) {
        this.userRoleId = userRoleId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (userId != null ? userId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users) object;
        if ((this.userId == null && other.userId != null) || (this.userId != null && !this.userId.equals(other.userId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Users[ userId=" + userId + " ]";
    }

    @XmlTransient
    public Collection<Routes> getRoutesCollection() {
        return routesCollection;
    }

    public void setRoutesCollection(Collection<Routes> routesCollection) {
        this.routesCollection = routesCollection;
    }
    
}
